package singleton;

//懒汉式
public class CreatSingleton1 {
    private static CreatSingleton1 singleton ;
    private CreatSingleton1() {
        System.out.println(Thread.currentThread().getName()+"正在调用构造方法...");
    }
    public synchronized static CreatSingleton1 getSingleton() {
        if (singleton == null) {
            singleton = new CreatSingleton1();
        }
        return singleton;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                CreatSingleton1.getSingleton();
            },String.valueOf(i)).start();

        }
    }
}
